// exp8_8_6a.cpp
#include <iostream>
#include <string>

template<class T>
T maxn(T arr[], int n)
{
    T max = arr[0];
    for (int i = 0; i < n; i++)
    {
        if (arr[i] > max)
            max = arr[i];
    }
    return max;
}

template <> 
std::string maxn<std::string>(std::string arr[], int n)
{
    int max = 0; 
    int tmp = 0;
    int idx = 0;
    for (int i = 0; i < n; i++)
    {
        tmp = arr[i].length();
        if (tmp > max)
        {
            max = tmp;
            idx = i;
        }
    }
    return arr[idx];
}

int main(void)
{
    using std::string;
    int arr[] = {2, 3, 1, 9,4,7};
    double arr2[] = {2.1, 3.7, 1.5, 19.9};
    string zoo[5] = {"Hello", "World", "anna", "Ben", "Celibrate"};
    std::cout << maxn(arr, 6) << "\n";
    std::cout << maxn(arr2, 4) << "\n";
    std::cout << maxn(zoo, 5) << "\n";

}
